package com.getpebble.android.util;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

public class HttpUtils {
    public static boolean hasInternetConnection(Context context) {
        boolean haveConnectedWifi = false;
        boolean haveConnectedMobile = false;
        for (NetworkInfo ni : ((ConnectivityManager) context.getSystemService("connectivity")).getAllNetworkInfo()) {
            if (ni.getType() == 1 && ni.isConnected()) {
                haveConnectedWifi = true;
            }
            if (ni.getType() == 0 && ni.isConnected()) {
                haveConnectedMobile = true;
            }
        }
        if (haveConnectedWifi || haveConnectedMobile) {
            return true;
        }
        return false;
    }

    public static boolean isWifiConnected(Context context) {
        for (NetworkInfo ni : ((ConnectivityManager) context.getSystemService("connectivity")).getAllNetworkInfo()) {
            if (ni.getType() == 1 && ni.isConnected()) {
                return true;
            }
        }
        return false;
    }
}
